/*
* Copyright (c) 2006 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_CRITICALSECTION_H
#define M_CRITICALSECTION_H

#ifdef WIN32
#include <windows.h> 
#else
#include <pthread.h>
#endif


namespace Engine
{	
#ifdef WIN32
	/**
	*   Class represent critical section wrapper.
	*/
	class CriticalSection
	{
	public:
		
		/** Constructor.
		*   Simply create mutex object.
		*/
		CriticalSection()
		{
			InitializeCriticalSection(&cs);
		}
		
		/** Destructor.
		*   Wait for mutex, release it and destroy.
		*/
		~CriticalSection()
		{
			DeleteCriticalSection(&cs);
		}
		
		/** Get owner ship.
		*/
		void Lock()
		{
			EnterCriticalSection(&cs);
		}
		
		/** Release owner ship.
		*/
		void Unlock()
		{
			LeaveCriticalSection(&cs);
		}
	private:
		
		/** Copy-constructor not implemented.
		*/
		CriticalSection( const CriticalSection & );
		
		/** Copy-assignment operator not implemented.
		*/
		CriticalSection & operator = ( const CriticalSection & );
		
		/** Critical section object.
		*/
		CRITICAL_SECTION cs;
	};
#endif
}

#endif
